package com.example;

import com.example.TestSort1.User;

import java.util.*;
import java.util.stream.Collectors;

public class Test {
    @org.junit.Test
    public void test1() {
        List<User> users = Arrays.asList(
                new User("120", "工位1", "工序1", "河南1"),
                new User("120", "工位2", "工序2", "河南2"),
                new User("121", "工位1", "工序1", "河南3"),
                new User("121", "工位2", "工序2", "河南4"),
                new User("122", "工位1", "工序1", "河南5"),
                new User("122", "工位21", "工序2", "河南6")
        );

        List<String> strings = Arrays.asList("120", "121", "122");
        List<User> u1 = new ArrayList<>();
        List<User> u2 = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            String s = strings.get(i);
            for (User user : users) {
                if(s.equals(user.getPartNo()) && i==0) {
                    u1.add(user);
                }if(s.equals(user.getPartNo()) && i==1){
                    u2.add(user);
                }
            }
        }

        System.out.println(u1);
        System.out.println(u2);

        if(u1.size() == u2.size()) {
            List<String> l1 = u1.stream().map(User::getWaitCode).collect(Collectors.toList());
            List<String> l2 = u1.stream().map(User::getWaitGroupCode).collect(Collectors.toList());
            boolean flag = false;
            for (User user : u2) {
                String waitCode = user.getWaitCode();
                String waitGroupCode = user.getWaitGroupCode();
                if(!l1.contains(waitCode) || !l2.contains(waitGroupCode)) {
                    flag = true;
                }
            }
            System.out.println(flag);

            if(!flag) {
                int size = u1.size();
                Set<String> s1 = new HashSet<>(l1);
                Set<String> s2 = new HashSet<>(l2);
                for (User user : users) {
                    String waitCode = user.getWaitCode();
                    String waitGroupCode = user.getWaitGroupCode();
                    String partNo = user.getPartNo();
                    s1.add(waitCode);
                    if(s1.size()>size) {
                        System.out.println("重复");
                    }
                    s2.add(waitGroupCode);
                    if(s2.size() > size) {
                        System.out.println("重复");
                    }
                }
            }
        }


//        Map<String, List<User>> collect = users.stream().collect(Collectors.groupingBy(User::getPartNo));
//        System.out.println(collect);


    }
// 推荐
    @org.junit.Test
    public void test2() {
        List<User> users = Arrays.asList(
                new User("120", "工位1", "工序1", "河南1"),
                new User("120", "工位2", "工序2", "河南2"),
                new User("121", "工位1", "工序1", "河南3"),
                new User("121", "工位2", "工序2", "河南4"),
                new User("122", "工位1", "工序1", "河南5"),
                new User("122", "工位21", "工序2", "河南6")
        );

        List<String> strings = Arrays.asList("120", "121", "122");

        User user = users.get(0);
        String partNo = user.getPartNo();
        Set<String> s1 = new HashSet<>();
        Set<String> s2 = new HashSet<>();
        for (User user1 : users) {
            if(partNo.equals(user1.getPartNo())) {
                s1.add(user1.getWaitCode());
                s2.add(user1.getWaitGroupCode());
            }
        }
        int size = s1.size();
        int size1 = s2.size();
        for (User user1 : users) {
            if(!partNo.equals(user1.getPartNo())) {
                String partNo1 = user1.getPartNo();
                String waitCode = user1.getWaitCode();
                String waitGroupCode = user1.getWaitGroupCode();
                s1.add(waitCode);
                s2.add(waitGroupCode);

                if(s1.size() != size || s2.size() != size1) {
                    System.out.println(partNo1);
                    System.out.println("重复");
                }
            }
        }


//        Map<String, List<User>> map = users.stream().collect(Collectors.groupingBy(User::getPartNo));
//
//        Set<Map.Entry<String, List<User>>> entries = map.entrySet();
//        for (Map.Entry<String, List<User>> entry : entries) {
//            String key = entry.getKey();
//            List<User> uss = entry.getValue();
//            Set<String> set = new HashSet<>();
//            Set<String> set1 = new HashSet<>();
//            for (User user : uss) {
//                String waitCode = user.getWaitCode();
//                String waitGroupCode = user.getWaitGroupCode();
//                set.add(waitCode);
//                set1.add(waitGroupCode);
//            }
//            int size = set.size();
//            int size1 = set1.size();
//            if(set.size() != size || set1.size() != size1) {
//                System.out.println(key);
//                System.out.println("重复");
//            }
//        }

    }
}
